package com.king.common.lang;

import lombok.Data;

import java.io.Serializable;

@Data
public class Result implements Serializable {
    private int status;//0成功, -1失败
    private String msg;
    private Object data;
    private String action;

    public static Result success() {
        return success(null);
    }

    public static Result success(Object data){
        return success("操作成功！",data);
    }

    public static Result fail(String msg){
        return fail(-1,msg);
    }

    public static Result success(String msg,Object data){
        Result r = new Result();
        r.setStatus(0);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }

    public static Result fail(int code,String msg){
        Result r = new Result();
        r.setStatus(code);
        r.setMsg(msg);
        r.setData(null);
        return r;
    }

    public Result action(String action) {
        this.setAction(action);
        return this;
    }
}
